package com.emr.web.controller.emr;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emr.common.annotation.Log;
import com.emr.common.enums.BusinessType;
import com.emr.module.domain.Emergency;
import com.emr.module.service.IEmergencyService;
import com.emr.module.service.IIcdService;
import com.emr.module.service.IPersonalService;
import com.emr.system.service.ISysUserService;
import com.emr.web.core.base.BaseController;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.common.base.AjaxResult;

/**
 * 临床医疗组 信息操作处理
 * 
 * @author emr
 * @date 2019-02-28
 */
@Controller
@RequestMapping("/module/emergency")
public class EmergencyController extends BaseController
{
    private String prefix = "module/emergency";
	
	@Autowired
	private IEmergencyService emergencyService;
	@Autowired
	private IPersonalService ipersonalService ;
	@Autowired
	private ISysUserService isysUserService;
	@Autowired
	private IIcdService icdService;
	
	@RequiresPermissions("module:emergency:view")
	@GetMapping()
	public String emergency()
	{
	    return prefix + "/emergency";
	}
	
	/**
	 * 查询临床医疗组列表
	 */
	@RequiresPermissions("module:emergency:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Emergency emergency)
	{
		startPage();
        List<Emergency> list = emergencyService.selectEmergencyList(emergency);
		return getDataTable(list);
	}
	
	/**
	 * 新增临床医疗组
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		mmap.put("hushi", isysUserService.selectUserAll());
		mmap.put("yisheng", isysUserService.selectyishengAll());
//		mmap.put("icd",icdService.selectIcdAll() );
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存临床医疗组
	 */
	@RequiresPermissions("module:emergency:add")
	@Log(title = "临床医疗组", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Emergency emergency)
	{		
		return toAjax(emergencyService.insertEmergency(emergency));
	}

	/**
	 * 修改临床医疗组
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Emergency emergency = emergencyService.selectEmergencyById(id);
		mmap.put("hushi", isysUserService.selecthushiAlls(Integer.valueOf(emergency.getHushiId())));
		mmap.put("yisheng", isysUserService.selectyishengAlls(Integer.valueOf(emergency.getYishengId())));
		mmap.put("emergency", emergency);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存临床医疗组
	 */
	@RequiresPermissions("module:emergency:edit")
	@Log(title = "临床医疗组", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Emergency emergency)
	{		
		return toAjax(emergencyService.updateEmergency(emergency));
	}
	
	/**
	 * 删除临床医疗组
	 */
	@RequiresPermissions("module:emergency:remove")
	@Log(title = "临床医疗组", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(emergencyService.deleteEmergencyByIds(ids));
	}
	
}
